Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[client] Adds signWithEckoWallet and quicksignWithEckoWallet functions #750

Merged
merged 6 commits into from
Aug 29, 2023

Conversation

ash-vd
Copy link
Contributor

@ash-vd ash-vd commented Aug 7, 2023

Adds two functions to sign a transaction with the Ecko Wallet API.

Usage, where unsignedTransaction is a IPactCommand:

const signWithEckoWallet = createEckoWalletSign();
await signWithEckoWallet(unsignedTransaction);
const quicksignWithEckoWallet = createEckoWalletQuicksign();
await quicksignWithEckoWallet(unsignedTransaction);

On both signWithEckoWallet and quicksignWithEckoWallet there are several helpers available:

const isInstalled = signWithEckoWallet.isInstalled();
const isConnected = await signWithEckoWallet.isConnected();
const accountInfo = await getAccountInfo();
await signWithEckoWallet.connect();

connect() is also automatically called when signing for a transaction

@vercel
Copy link

vercel bot commented Aug 7, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

5 Ignored Deployments
Name Status Preview Comments Updated (UTC)
alpha-docs ⬜️ Ignored (Inspect) Visit Preview Aug 29, 2023 9:19am
docs-storybook ⬜️ Ignored (Inspect) Visit Preview Aug 29, 2023 9:19am
immutable-records ⬜️ Ignored (Inspect) Visit Preview Aug 29, 2023 9:19am
react-ui ⬜️ Ignored (Inspect) Visit Preview Aug 29, 2023 9:19am
tools ⬜️ Ignored (Inspect) Visit Preview Aug 29, 2023 9:19am

@ash-vd ash-vd changed the title Adds signWithEckoWallet and quicksignWithEckoWallet functions [client] Adds signWithEckoWallet and quicksignWithEckoWallet functions Aug 8, 2023
Comment on lines 19 to 23
if (checkStatusResponse?.status === 'fail') {
return false;
}

return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the best way to check for active status or should we return true on a positive signal?

Copy link
Contributor Author

@ash-vd ash-vd Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although Ecko returns a fail status when it isn't connected, I agree that it might be better to turn things around to only return true when the returned status is success. Then it'll also return false when Ecko returns capybara or something else that's just weird.

Comment on lines +36 to +40
await window.kadena?.request<IEckoConnectOrStatusResponse>({
method: 'kda_connect',
networkId,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this ever throw?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only when request doesn't exist on window.kadena, which is checked in isConnected. I've now added an extra check in that function to check if window.kadena.request is there.

Copy link
Contributor

@Takadenoshi Takadenoshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM aside from two small questions

*/
export interface IEckoSignSingleFunction
extends ISingleSignFunction,
ICommonEckoFunctions {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mixing a function with properties might lead to a confusing api for users since function itself has some methods like apply, call ,...
what if we instead add the sign as a method like this

export interface IEckoSignFunction {
   isInstalled: typeof isInstalled;
   isConnected: typeof isConnected;
   connect: typeof connect;
   sign : ISingleFunction,
   quickSign : ISingleFunction,
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've thought about that, but we wanted to make the usage of this function the same as the other functions to allow drop-in replacement.

@javadkh2
Copy link
Collaborator

javadkh2 commented Aug 21, 2023

Maybe instead of exposing createEckoWalletSign and createEckoWalletQuicksign we can have one creator like createEchoWalletConnector

export interface IEckoWalletConnector {
   isInstalled: () => boolean;
   isConnected: (networkId:string) => Promise<boolean>;
   connect: (networkId:string) => Promise<boolean>;
   sign : ISingleSignFunction,
   quickSign : ISignFunction,
}
const echoWalletConnector: IEckoWalletConnector = createEchoWalletConnector();

What do you say @alber70g
Maybe we even can have a separate package for connectors? like @kadena/wallet-connectors
then we can focus of creating some connectors for common wallets there.

@alber70g
Copy link
Member

Maybe instead of exposing createEckoWalletSign and createEckoWalletQuicksign we can have one creator like createEchoWalletConnector

export interface IEckoWalletConnector {
   isInstalled: () => boolean;
   isConnected: (networkId:string) => Promise<boolean>;
   connect: (networkId:string) => Promise<boolean>;
   sign : ISingleSignFunction,
   quickSign : ISignFunction,
}
const echoWalletConnector: IEckoWalletConnector = createEchoWalletConnector();

What do you say @alber70g Maybe we even can have a separate package for connectors? like @kadena/wallet-connectors then we can focus of creating some connectors for common wallets there.

There are multiple things at hand here

  1. as said in above comment, we wanted to make it as uniform as possible when working with the wallets and sign functions
  2. we want to deprecate sign at some point. It's easier to deprecate that function when it has its own separate code-branch
  3. A separate package would be nice. This would provide a clear entry point into all the external connections that can be made and provide an easy way to integrate new connections. Let's think about this, and create an issue for that

@LindaOrtega
Copy link
Contributor

Do we still want to merge this pull request?

@alber70g alber70g force-pushed the feat/signWithEckoWallet branch 4 times, most recently from 3803545 to 3304085 Compare August 29, 2023 07:50
@changeset-bot
Copy link

changeset-bot bot commented Aug 29, 2023

🦋 Changeset detected

Latest commit: 8748d4b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@kadena/client Minor
@kadena/tools Patch
@kadena/client-examples Patch
@kadena/cookbook Patch
@kadena/pactjs-generator Minor
@kadena/pactjs-cli Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@alber70g alber70g merged commit b8b8661 into main Aug 29, 2023
4 checks passed
@alber70g alber70g deleted the feat/signWithEckoWallet branch August 29, 2023 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants